<template>
  <div class="app-container">
    <div class="block">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-input v-model="listQuery.title" size="mini" placeholder="标题" />
        </el-col>

        <el-col :span="6">
          <el-button
            type="success"
            size="mini"
            icon="el-icon-search"
            @click.native="search"
            >{{ $t("button.search") }}</el-button
          >
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-refresh"
            @click.native="reset"
            >{{ $t("button.reset") }}</el-button
          >
        </el-col>
      </el-row>
      <br />
      <el-row>
        <el-col :span="24">
          <el-button
            v-permission="['/banner/edit']"
            type="success"
            size="mini"
            icon="el-icon-plus"
            @click.native="add"
            >{{ $t("button.add") }}</el-button
          >

          <el-button
            v-show="shopCategory.show"
            type="success"
            size="mini"
            icon="el-icon-edit"
            :disabled="shopCategory.disabled"
            @click.native="setBanner"
            >选中banner</el-button
          >
          <el-button
            v-permission="['/banner/delete']"
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click.native="remove"
            >{{ $t("button.delete") }}</el-button
          >
        </el-col>
      </el-row>
    </div>

    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      @current-change="handleCurrentChange"
      @row-click="clickRow"
    >
      <el-table-column label="ID">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="标题">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="类别">
        <template slot-scope="scope">
          {{ scope.row.type }}
        </template>
      </el-table-column>
      <el-table-column label="打开界面">
        <template slot-scope="scope">
          {{ scope.row.page }}
        </template>
      </el-table-column>
      <el-table-column label="参数">
        <template slot-scope="scope">
          {{ scope.row.param }}
        </template>
      </el-table-column>
      <el-table-column label="图片">
        <template slot-scope="scope">
          <img :src="scope.row.idFile" style="width:200px;" />
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :title="formTitle" :visible.sync="formVisible" width="70%">
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row>
          <el-col :span="12">
            <el-row>
              <el-col :span="12">
                <el-form-item label="banner图片">
                  <el-upload
                    class="upload-demo"
                    drag
                    multiple="false"
                    :action="uploadUrl"
                    :headers="uploadHeaders"
                    :before-upload="handleBeforeUpload"
                    :on-success="handleUploadSuccess"
                  >
                    <i class="el-icon-upload" />
                    <div class="el-upload__text">上传图片</div>
                  </el-upload>
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="12">
            <el-row>
              <el-col :span="24">
                <el-form-item label="标题" prop="title">
                  <el-input v-model="form.title" minlength="1" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="打开的界面">
                  <el-input v-model="form.page" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="参数" prop="param">
                  <el-input v-model="form.param" type="textarea" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="类型">
                  <el-select v-model="form.type" placeholder="请选择">
                    <el-option
                      v-for="item in options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
        </el-row>

        <el-form-item>
          <el-button type="primary" @click="save">{{
            $t("button.submit")
          }}</el-button>
          <el-button @click.native="formVisible = false">{{
            $t("button.cancel")
          }}</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script src="./banner.js"></script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>
